<template>
	<view>
		<u-navbar :background="{background: '#fff'}" back-icon-color="#222222" title-color="#222222"
			title="确认预约信息"></u-navbar>
		<view class=""
			style="margin: 22rpx 28rpx;background: 20rpx;background: #fff;padding-bottom: 54rpx;border-radius: 20rpx;">
			<view class="" style="display: flex;align-items: center;justify-content: space-between;padding: 36rpx;">
				<view class="" style="font-size: 30rpx;">
					加号信息
				</view>
				<view class="" style="font-size: 26rpx;color: #1A9EFF;" @tap="back">
					更改患者
				</view>
			</view>
			<view class="" style="font-size: 28rpx;display: flex;align-items: center;padding: 0 36rpx;">
				<view class="" style="color: #666666;">
					就诊人
				</view>
				<view class="" style="padding-left: 84rpx;">
					{{patient.patient_name}} {{patient.patient_mobile}}
				</view>
			</view>
			<view class="" style="font-size: 28rpx;display: flex;align-items: center;padding: 36rpx;">
				<view class="" style="color: #666666;">
					就诊机构
				</view>
				<view class="" style="padding-left: 57rpx;">
					{{clinic.name}}
				</view>
			</view>
			<view class="" style="font-size: 28rpx;display: flex;align-items: center;padding: 0 36rpx;">
				<view class="" style="color: #666666;">
					就诊医生
				</view>
				<view class="" style="padding-left: 57rpx;">
					{{doctor_list.doctor_name}}-{{doctor_list.department_name}}-{{doctor_list.doctor_title}}
				</view>
			</view>
			<view class="" style="font-size: 28rpx;display: flex;align-items: center;padding: 36rpx;">
				<view class="" style="color: #666666;">
					门诊类型
				</view>
				<view class="" style="padding-left: 57rpx;">
					普通号
				</view>
			</view>
			<view class="" style="font-size: 28rpx;display: flex;align-items: center;padding: 0 36rpx;">
				<view class="" style="color: #666666;">
					就诊时间
				</view>
				<view class="" style="padding-left: 57rpx;">
					{{week}} {{time}} {{clinic_type==2 ? '下午' :'上午'}}
				</view>
			</view>
		</view>
		<!-- 温馨提示 -->
		<!-- <view class="" style="font-size: 26rpx;color: #666666;padding-left: 63rpx;">
			温馨提示
		</view>
		<view class="" style="font-size: 26rpx;color: #666666;padding: 22rpx 63rpx;">
			*号源由医生本人提供、与医生无关。到医院需按医院门
			诊价格缴纳医事服务费
		</view> -->
		<u-popup v-model="show" mode="bottom" border-radius="14">
			<view class="" style="margin: 28rpx;
					box-shadow: 0px 0px 10rpx 0px rgba(70,70,70,0.05);background: #fff;border-radius: 20rpx;">
				<view class="" style="padding: 31rpx;font-size: 32rpx;font-weight: bold;">
					支付方式
				</view>
				<view class="flex align-center margin-top" @tap="radio=1;"
					style="padding: 0 31rpx 0 31rpx;display: flex;align-items: center;justify-content: space-between;padding-top: 15rpx;">
					<view class="" style="display: flex;align-items: center;">
						<image src="../../static/index/zfbpay.png" mode="" style="width: 70upx;height: 70upx;"></image>
						<view class="flex-sub margin-left-sm" style="font-size: 28rpx;padding-left: 12rpx;">
							微信支付
						</view>
					</view>

					<radio :checked="radio==1?true:false" color="#1A9EFF" style="transform: scale(.7);"></radio>
				</view>
				<view class="btn" @tap="queren">
					立即支付
				</view>
				<!-- <view class="" style="height: 30rpx;"></view> -->
			</view>
		</u-popup>
		<!-- 底部栏 -->
		<view class="" style="width: 100%;height: 192rpx;background: #fff;position: fixed;bottom: 0;">
			<view class="btn" @tap="show=true">
				确认加号
			</view>
			<!-- queren -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				patient: {},
				clinic: {},
				clinic_type: null,
				doctor_id: null,
				time: null,
				week: null,
				doctor_list: {},
				radio: 1,
				show: false

			};
		},
		//方法
		methods: {
			back() {
				uni.navigateBack()
			},
			detail() {
				this.api({
					url: '/api//doctor/details',
					method: 'post',
					data: {
						doctor_id: this.doctor_id
					}
				}).then(res => {
					this.doctor_list = res.data
				})
			},
			queren() {
				var date = new Date();
				this.api({
					url: '/api//register/createOrder',
					method: 'post',
					data: {
						doctor_id: this.doctor_id,
						patient_id: this.patient.patient_id,
						clinic_date: date.getFullYear() + '-' + this.time,
						clinic_type: this.clinic_type,
						clinic_id: this.clinic.id,
						type: 'wechat',
					}
				}).then(res => {
					if (res.data.response == '') {
						uni.showToast({
							title: '支付成功！',
							icon: 'none'
						}) 
						setTimeout(() => {
							uni.navigateTo({
								url: '/user/makedetail/makedetail?id=' + res.data.order_id
							})
						}, 1000)
					}else{
						console.log(res,'123132132123');
						uni.requestPayment({
								provider: 'wxpay',
								timeStamp: res.data.response.timeStamp,
								nonceStr: res.data.response.nonceStr,
								package: res.data.response.package,
								signType: res.data.response.signType,
								paySign: res.data.response.paySign,
							success: function(data) {
								setTimeout(() => {
									uni.navigateTo({
										url: '/user/makedetail/makedetail?id='+res.data.order_id
									})
								}, 1000)
							},
							fail: function(err) {
								uni.showToast({
									title: '支付失败',
									icon: 'none'
								})
							}
						});
					}
					


				})
			}
		},
		//首页渲染
		onLoad(op) {
			console.log(op)
			this.patient = JSON.parse(op.patient_id)
			this.clinic = JSON.parse(op.clinic_id)
			this.clinic_type = op.clinic_type
			this.doctor_id = op.doctor_id
			this.time = op.time
			this.week = op.week
			this.detail()
		},

	}
</script>

<style lang="scss" scoped>
	page {
		background: #F8F8F8;
	}

	.btn {

		height: 80rpx;
		background: linear-gradient(180deg, #1A9EFF, #0FB8FF);
		border-radius: 40rpx;
		margin: 60rpx 115rpx;
		text-align: center;
		color: #fff;
		line-height: 80rpx;
	}
</style>
